package demo2;

import java.net.PasswordAuthentication;

class Test4 {

    private String name = "pl";
    private int pass = 123456;

    public void fun(String name, int pass) throws UserNameException, UserPassException {

        if (!this.name.equals(name)) {
            throw new UserNameException("名字错误");
        }

        if (this.pass != pass) {
            throw new UserPassException("密码错误");
        }
    }

}
public class Test3 {
    public static void main(String[] args) {
        Test4 test4 = new Test4();

        try {
            test4.fun("pl",123465);
        }catch (UserNameException e) {
            e.printStackTrace();
            System.out.println("捕捉到了 UserNameException 异常 ");
        }catch (UserPassException userPassException) {
            userPassException.printStackTrace();
            System.out.println("捕捉到了 UserPassException 异常 ");
        }

    }
}
